//
//  ZDDStatusToolbar.swift
//  小蜗牛_新浪微博
//
//  Created by 周冬冬 on 16/6/29.
//  Copyright © 2016年 我的mac. All rights reserved.
//

import UIKit

class ZDDStatusToolbar: UIView {

    var retweetButton: UIButton?
    var commentButton: UIButton?
    var unlikeButton: UIButton?
    var status:ZDDStatuses?{
    
        didSet{
              retweetButton?.setTitle(status?.repostsStr, forState: UIControlState.Normal)
              commentButton?.setTitle(status?.commentsStr, forState: UIControlState.Normal)
              unlikeButton?.setTitle(status?.attitudesStr, forState: UIControlState.Normal)
        
        }
    
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
    backgroundColor = UIColor.whiteColor()
         retweetButton = addChildButtons("timeline_icon_retweet", title: "转发")
         commentButton = addChildButtons("timeline_icon_comment", title: "评论")
         unlikeButton = addChildButtons("timeline_icon_unlike", title: "赞")
        // 分割线
        let line1 = addChildLines()
        let line2 = addChildLines()
        //添加约束
        line1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton!.snp_trailing)
            make.centerY.equalTo(self)
        }
        line2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentButton!.snp_trailing)
            make.centerY.equalTo(self)
        }
        //转发
        retweetButton!.snp_makeConstraints { (make) -> Void in
            make.leading.top.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        }
        //评论
        commentButton!.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton!.snp_trailing)
            make.width.equalTo(unlikeButton!)
        }
        //赞
        unlikeButton!.snp_makeConstraints { (make) -> Void in
            make.trailing.top.bottom.equalTo(self)
            make.leading.equalTo(commentButton!.snp_trailing)
        }
    
    
    }
    //创建Button
    private func addChildButtons(imageName:String,title:String)->UIButton{
    
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
          button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        addSubview(button)
        return button
    
    }
    private func addChildLines()->UIImageView{
    
        let img = UIImageView(imageName: "timeline_card_bottom_line")
        
        addSubview(img)
        return img
    
    
    }
}



















